<?php

namespace app\components;

use app\helpers\Coin;
use Yii;
use yii\di\Instance;

class PriceUnit
{
    public $price_unit;

    public static function setTotal($new_price_unit = Coin::UNIT_CNY)
    {
        /** @var  $instance self */
        $instance = new self();
        $instance->set($new_price_unit);
        Yii::$container->setSingleton(self::class, $instance);
    }

    /**
     * @return int
     */
    public static function getTotal()
    {
        /** @var  $instance self */
        $instance = Yii::$container->get(self::class);
        return $instance? $instance->price_unit : Coin::UNIT_CNY;
    }

    public function set($new_val)
    {
        $this->price_unit = $new_val;
        return $this;
    }
}
